package cm.swagger.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author: yxh
 * @Description: 注入自定义拦截器
 * @Date: Created in 2022/11/1 14:08
 * @Modified By:
 */

@Configuration
public class SetRegistryInterceptor extends WebMvcConfigurationSupport {

    /** 添加拦截器 **/
    @Override
    public void addInterceptors(InterceptorRegistry interceptorRegistry) {
        interceptorRegistry
                .addInterceptor(new SetInterceptor())
                //拦截资源
                .addPathPatterns("/**")
                // 不需要拦截资源 静态资源
                .excludePathPatterns("/js/**", "/css/**", "/images/**", "/lib/**","/fonts/**")
                // swagger-ui
                .excludePathPatterns("/swagger-resources/**", "/webjars/**",
                        "/v2/**","/springfox-swagger-ui/**","/swagger-ui/**", "/swagger-ui.html/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
    }
}
